/**
 * Framework for batch testing user profile models
 * Final project by Sergey Nepomnyachiy and Julia Polchin
 * Supervisor: Tsvi Kuflik
 *
 */
package backend;

import static org.junit.Assert.*;

import java.util.Vector;

import org.junit.Test;

/**
 * Unit testing stats class
 * @author Sergey and Julia
 *
 */
@SuppressWarnings("boxing")
public class TestStats {

	/**
	 *  Test correlation close to 1
	 * 
	 */
	@Test
	public void testCorr1() {
		Double[] arr1 = { 0.1, 0.2, 0.3 };
		Double[] arr2 = { 0.15, 0.19, 0.26};
		
		Vector<Double> v1 = new Vector<Double>();
		Vector<Double> v2 = new Vector<Double>();
		for (Double d : arr1) 
			v1.add(d);
		for (Double d : arr2) 
			v2.add(d);
		
		Double corr = Stats.getCorrelation(v1, v2);
		assertTrue( corr.equals(0.98782916114726));
	}

	/**
	 *  Test negative correlation of -0.5
	 * 
	 */
	@Test
	public void testCorr2() {
		Double[] arr1 = { 1.0, 2.0, 3.0};
		Double[] arr2 = { 2.0,3.0,1.0};
		
		Vector<Double> v1 = new Vector<Double>();
		Vector<Double> v2 = new Vector<Double>();
		for (Double d : arr1) 
			v1.add(d);
		for (Double d : arr2) 
			v2.add(d);
		
		Double corr = Stats.getCorrelation(v1, v2);
		assertTrue( corr.equals(-0.5));
	}

	/**
	 *  Test longer vector
	 */
	@Test
	public void testCorr3() {
		Double[] arr1 = { 1.0, 2.3, 3.1, 4.8, 5.6, 6.3};
		Double[] arr2 = { 2.6, 2.8, 3.1, 4.7, 5.1, 5.3};
		
		Vector<Double> v1 = new Vector<Double>();
		Vector<Double> v2 = new Vector<Double>();
		for (Double d : arr1) 
			v1.add(d);
		for (Double d : arr2) 
			v2.add(d);
		
		Double corr = Stats.getCorrelation(v1, v2);
		assertTrue( corr.equals(0.9740560595195411));
	}
	
	/**
	 *  Test MAE
	 */
	@Test
	public void testMAE() {
		Double[] arr1 = { 1.0, 2.0, 3.0, 4.0, 5.0};
		Double[] arr2 = { 2.0, 1.0, 5.0, 2.0, 8.0};
		
		Vector<Double> v1 = new Vector<Double>();
		Vector<Double> v2 = new Vector<Double>();
		for (Double d : arr1) 
			v1.add(d);
		for (Double d : arr2) 
			v2.add(d);
		
		Double mae = Stats.getMAE(v1, v2);
		assertTrue( mae.equals(1.8));
	}
}
